package cn.aylog.example;

import sun.rmi.runtime.Log;

/**
 * 使用分治算法解决汉诺塔问题
 * 1.将n-1个从A移动到B
 * 2.将第一个从A移动到C
 * 3.将n-1个从B上的移动到C
 */
public class HanoiTower {
    public static void main(String[] args) {
        hanoiTower(60, 'A', 'B', 'C');
    }
    public static void hanoiTower(int num, char a, char b, char c) {
        if (num == 1) {
            System.out.println("第1个" +a + "->" + c);
        } else {
            hanoiTower(num - 1, a, c, b);
            System.out.println("第"+num+"个" + a + "->" + c);
            hanoiTower(num - 1, b, a, c);
        }
    }
}
